<?php
ob_start();
define('ROOT_PATH', '/var/www/html/new/d');
include 'common/autoload.php';
include 'common/header.html';
include 'common/left.html';
include 'common/page.php';
include 'common/area.inc.php';
include 'common/Prod_Common.php';
$out_html=ob_get_contents();
ob_end_clean();
use \pft\Prod\Product;
use \pft\Member\MemberAccount;

$lvl_limit = array(0, 2, 6, 9);
if(!in_array($_SESSION['dtype'], $lvl_limit)) {
    exit('不合法的身份！');
}
if ($_SESSION['dtype']==6 && !strpos($_SESSION['qx'],'upProd')) {
    if(MemberAccount::GetMemType($_SESSION['sid'])!=0) {
        exit('您的上级不是供应商身份，无法发布产品。');
    }
}

$status = 3;
$title_status = array(
    1 => '自供应产品',
    2 => '下架产品',
    3 => '待发布产品',
);
$page_title = $title_status[$status];

if(!is_numeric($status)) {
    exit('非法的参数！');
}


$ticketOption = array(
    'apply_limit'=> $status,
);

if(!empty($_GET['s_input'])) {
    $p_title = trim(strip_tags($_GET['s_input']));
    $params['title'] = addslashes($p_title);
}

if (!empty($_GET['apply_did']) && $_SESSION['sdtype']==9) {
    $params['applyer'] = intval($_GET['apply_did']);
}
if (is_numeric($_GET['d_province']) && $_GET['d_province']>0) {
    $params['area'] = $_GET['d_province'] . '|';
    if (is_numeric($_GET['d_city']) && $_GET['d_city']>0) {
        $params['area'] .= $_GET['d_city'];
    }
}



if(!empty($_GET['s_title'])) {
    $params['title'] = safetxt($_GET['s_title']);
}

$soap   = SoapInit::GetSoapInside();
$obj    = new Product($GLOBALS['le'], $soap);

$add_list = array('A'=>'票类','B'=>'票类','C'=>'客房','D'=>'商品','F'=>'套票');
$sta_list = array('0'=>'<span class="red">[未审核]</span>','','<span class="red">[被拒绝]</span>');
$debug    = false;

//TODO::获取会员数据
$memberNames = include dirname(__FILE__) . '/module/link_product/Member.cache.php';
$data = array();
// 未发布票类的产品
$data['tickets'] = array();
$data['lands'] = $obj->GetEmptyProduct($_SESSION['sid'], $params['title']);
$data['total'] = count($data['lands']);

//导览账号配置
$id_list = array(1433,4971,7508,94,1229,7517);
if(isset($_REQUEST['act']) && $_REQUEST['act']=="Export")
{   
	$filename=date('YmdHis').'分销商产品列表';
    $Excel[0]['a']='省';
    $Excel[0]['b']='市';
    $Excel[0]['c']='景区ID';
    $Excel[0]['d']='景区名称';
    $Excel[0]['e']='供应商';
    $Excel[0]['f']='状态';
	$i=2;
    foreach($data['lands'] as $k=> $prod){
        list($q,$sort[]) = explode('|', $prod['area']);
    }
    array_multisort($sort, $data['lands']);//根据地区来排序
    foreach($data['lands'] as $prod){
        list($prov, $city) = explode('|', $prod['area']);
        if(count($data['tickets'][$prod['id']])){
            foreach($data['tickets'][$prod['id']] as $key => $ticket){
                $Excel[$i]['a']=$areas[$prov];
                $Excel[$i]['b']=$areas[$city];
                $Excel[$i]['c']=$prod['id'];
                $Excel[$i]['d']=$prod['title'].$ticket['title'];
                $Excel[$i]['e']=$memberNames[$prod['apply_did']];
                $Excel[$i]['f']=($status==1)? '在售':'仓库';
                $i++;
            }
        }
    }
	$xls = new SimpleExcel('UTF-8', true,'land');
    $xls->addArray($Excel);
    $xls->generateXML($filename);
	exit;
}  
echo $out_html;
//include TPLPATH.'prodlists_sync.tpl';
$debug = $_GET["debug"];
if(!isset($debug)){
	include('tpl/prodlists_sync.tpl');
}else{
	include('tpl/prodlists_sync_test.tpl');
}
include 'common/footer.html';
?>